// pages/mine/mine.js
const app = getApp();
const util = require("../../utils/util.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    m1text: "LADY JESSICA",
    mineList: [
      { list: "我的尺寸" , url: "mySize/mySize" },
      { list: "我的优惠券", url: "coupon/coupon" },
      { list: "收货地址" , url: "address/address"},
      { list: "关于我们" , url: "about/about" }
    ],
    isBind: true,
    windowWidth: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.getSystemInfo({
      success: function (res) {
        // console.log(res.windowWidth)
        // console.log(res.windowHeight)
        that.setData({
          windowWidth: res.windowWidth
        })
        // 请求订单数量
        let sizeUrl = app.globalData.baseUrl + "weixin/ordersNum"
        let cid = wx.getStorageSync('cid')
        let data = {
          cid: cid
        }
        util.requestLoading(sizeUrl, data, "GET").then(res => {
          let grids = [
            { img: "../../images/mine/pay.png", num: res.data.waitPay, text: "待支付", url: "myform/myform?activeIndex=1&sliderOffset=" + (that.data.windowWidth * 0.1875) },
            { img: "../../images/mine/shipments.png", num: res.data.waitSend, text: "待发货", url: "myform/myform?activeIndex=2&sliderOffset=" + (that.data.windowWidth * 0.36875) },
            { img: "../../images/mine/receiving.png", num: res.data.waitReceive, text: "待收货", url: "myform/myform?activeIndex=3&sliderOffset=" + (that.data.windowWidth * 0.55) },
            { img: "../../images/mine/after_sale.png", text: "找售后", url: "lookforAfterSale/lookforAfterSale" }
          ]
          that.setData({
            grids: grids
          })
        })
        
      },
    })
  },
  getUserInfo: function (e) {
    // console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    let phone = wx.getStorageSync('phone').length
    if (phone == 11) {
      that.setData({
        isBind: false
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})